home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / yacas_alg / yacas_morphos / share / yacas / include / lispio.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  2.5 KB  |  97 lines

  1. /** \file lispio.h
  2.  * definitions of pure input output classes.
  3.  */
  4.  
  5.  
  6. #ifndef __lispio_h__
  7. #define __lispio_h__
  8.  
  9. #include "yacasbase.h"
  10.  
  11. // Hope this forward declaration doesn't screw us over...
  12. class InputDirectories;
  13. class InputStatus : public YacasBase
  14. {
  15. public:
  16.     InputStatus() : iFileName("none") , iLineNumber(-1)  {};
  17.     ~InputStatus();
  18.     void SetTo(LispCharPtr aFileName);
  19.     void RestoreFrom(InputStatus& aPreviousStatus);
  20.     inline LispInt LineNumber();
  21.     inline LispCharPtr FileName();
  22.     inline void NextLine();
  23. private:
  24.     LispCharPtr iFileName;
  25.     LispInt    iLineNumber;
  26. };
  27.  
  28. inline LispInt InputStatus::LineNumber()
  29. {
  30.     return iLineNumber;
  31. }
  32. inline LispCharPtr InputStatus::FileName()
  33. {
  34.     return iFileName;
  35. }
  36. inline void InputStatus::NextLine()
  37. {
  38.     iLineNumber++;
  39. }
  40.  
  41. /** \class LispInput : pure abstract class declaring the interface
  42.  *  that needs to be implemented by a file (something that expressions
  43.  *  can be read from).
  44.  */
  45. class LispInput : public YacasBase
  46. {
  47. public:
  48.     /** Constructor with InputStatus. InputStatus retains the information
  49.      * needed when an error occurred, and the file has already been
  50.      * closed.
  51.      */
  52.     LispInput(InputStatus& aStatus) : iStatus(aStatus) {};
  53.     virtual ~LispInput();
  54.  
  55.     /// Return the next character in the file
  56.     virtual LispChar Next() = 0;
  57.  
  58.     /** Peek at the next character in the file, without advancing the file
  59.      *  pointer.
  60.      */
  61.     virtual LispChar Peek() = 0;
  62.  
  63.     virtual InputStatus& Status() const {return iStatus;};
  64.  
  65.     /// Check if the file position is past the end of the file.
  66.     virtual LispBoolean EndOfStream() = 0;
  67.     /** StartPtr returns the start of a buffer, if there is one.
  68.      * Implementations of this class can keep the file in memory
  69.      * as a whole, and return the start pointer and current position.
  70.      * Especially the parsing code requires this, because it can then
  71.      * efficiently look up a symbol in the hash table without having to
  72.      * first create a buffer to hold the symbol in. If StartPtr is supported,
  73.      * the whole file should be in memory for the whole period the file
  74.      * is being read.
  75.      */
  76.     virtual LispCharPtr StartPtr() = 0;
  77.     virtual LispInt Position() = 0;
  78. protected:
  79.     InputStatus& iStatus;
  80. };
  81.  
  82. /** \class LispOutput : interface an output object should adhere to.
  83.  */
  84. class LispOutput : public YacasBase
  85. {
  86. public:
  87.     virtual ~LispOutput();
  88.     /// Write out one character.
  89.     virtual void PutChar(LispChar aChar) = 0;
  90.  
  91. public:
  92.     void Write(LispCharPtr aString);
  93. };
  94.  
  95. #endif
  96.  
  97.